
import React from 'react';
import { Navigate } from 'react-router-dom';

function AuthRoute(props: any) {
  const { user, role: routeRole, backUrl, component: Component } = props;

  // 如果用户有权限，就渲染对应的组件
  if (user.role && user.role.includes(routeRole)) {
    return <Component />;
  } else {
    // 如果没有权限，返回配置的默认路由
    return <Navigate to={backUrl} />;
  }
}

export default AuthRoute;
